package com.jie.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jie.reggie.commen.BaseContext;
import com.jie.reggie.commen.R;
import com.jie.reggie.entity.Orders;
import com.jie.reggie.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 曾豪杰
 * @Date: 2022/09/04/20:44
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        log.info("订单数据：{}",orders);
        ordersService.submit(orders);
        return R.success("用户下单成功");
    }
    @GetMapping("/userPage")
    public R<List<Orders>> page(@RequestParam Map map){
        String page = map.get("page").toString();
        String pageSize = map.get("pageSize").toString();

        Page<Orders> page1=new Page<Orders>(Long.parseLong(page),Long.parseLong(pageSize));
        LambdaQueryWrapper<Orders> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(Orders::getUserId, BaseContext.getCurrentId());
        List<Orders> orderList = ordersService.list(queryWrapper);

        return R.success(orderList);
    }
}
